package itcast.shops.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import itcast.service.ShopsService;
import itcast.service.ShopsServiceimpl;

/**
 * 在购物车界面，修改商品数量
 */
@WebServlet("/updateshopServlet")
public class UpdateshopServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateshopServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//1、设置编码
		request.setCharacterEncoding("utf-8");	
		response.setCharacterEncoding("utf-8");	
		//2、存储用户id，商品id，
		String shopid=request.getParameter("shopid");
		String shopcount=request.getParameter("shopcount");
		//3、调用service
		ShopsService service=new ShopsServiceimpl();
		service.updateshopcount(shopid,shopcount);
		//4、更新完成返回到原来界面
		response.sendRedirect(request.getHeader("Referer"));
	}

}
